/*
 * @Author: ChunLai
 * @Date: 2022-03-30 17:37:12
 * @LastEditTime: 2025-11-27 13:38:29
 * @Description: 数据字典配置
 * @FilePath: \01.latest-short-insure\src\store\modules\dictionary.js
 */

import {
  holderModeList,
  yesNoModeList,
  sexModeList,
  xubaoModeList,
  crsCodeList,
  shebaoList,
} from "@/config/com_dics.js";

const state = {
  /* ===== 各家保司特殊字段 ===== */
  //有效期长期默认值
  longTime: "9999-12-31",
  // 出生证是否限制有效期 -1-自选 1-固定3周岁前一天 2固定出生日期+2 3固定出生日期+3 4-固定4周岁前一天  9999长期
  idType11ValidFixed: -1,
  // 户口簿是否限制有效期 -1-自选 1-固定16周岁前一天 2固定出生日期+16 9999长期
  idType3ValidFixed: -1,
  // birthAddValue: 0, // 替换为page_json中beginInsDay
  gysFullName: "", // 产品保司全名
  gysIntroHtml: "", // 客户告知书合并内容

  /* ===== 单字段配置 ===== */
  normalOcuu: ["学生", "儿童"],
  normalOcuuKey: "name",
  ocuuClassName: "类",

  detailAddrRule: "村/组/号/室/队/院/房/楼/栋",
  noneOcrCheckIdCard: false, // 不需要ocr识别证件照信息(默认false需要)

  /* ===== 各家保司选择列表 ===== */
  /* = 常规通用码表(不可配置) = */
  holderTypeList: holderModeList, //投保者类型
  socialSecList: shebaoList, //是否有社保
  sexList: sexModeList,
  renewList: xubaoModeList,
  yesNoCheckList: yesNoModeList, // 常规是否选择
  // 扣款方式
  kkfsList: [
    {
      keyId: "1",
      text: "微信支付(推荐)",
    },
    {
      keyId: "2",
      text: "银行卡扣款",
    },
  ],

  /* = 常规通用码表(actionStore设置默认值,可在json中配置) = */
  // 个税居民类型
  crsIdTypeList: [],
  idTypeList: [
    {
      keyId: "0",
      text: "身份证",
      bbr: true,
      syr: true,
      tbr: true,
    },
  ],
  relationship: [
    {
      keyId: "0",
      text: "配偶",
      bbr: true,
      syr: true,
    },
  ],
  bankList: [],
  nationList: [],
};

const getters = {
  longTime: (state) => state.longTime,
  gysFullName: (state) => state.gysFullName,
  gysIntroHtml: (state) => state.gysIntroHtml,
  idType3ValidFixed: (state) => state.idType3ValidFixed,
  idType11ValidFixed: (state) => state.idType11ValidFixed,
  kkfsList: (state) => state.kkfsList, //扣款方式
  detailAddrRule: (state) => state.detailAddrRule,
  yesNoCheckList: (state) => state.yesNoCheckList,
  sexList: (state) => state.sexList,
  renewList: (state) => state.renewList,
  holderTypeList: (state) => state.holderTypeList,
  socialSecList: (state) => state.socialSecList,
  idTypeList: (state) => state.idTypeList,
  // 客户证件类型
  applicantIdTypeList: (state) => {
    return state.idTypeList.filter((item) => item.tbr || item.tbr !== false);
  },
  insuredIdTypeList: (state) => {
    return state.idTypeList.filter((item) => item.bbr || item.bbr !== false);
  },
  // 客户投保关系
  relationship: (state) => state.relationship,
  bbrToTbrRela: (state) => {
    return state.relationship.filter((item) => item.bbr || item.bbr !== false);
  },
  crsIdTypeList: (state) => state.crsIdTypeList,
  // 保单页-银行卡
  bankList: (state) => state.bankList,
  nationList: (state) => state.nationList,
  normalOcuu: (state) => state.normalOcuu,
  normalOcuuKey: (state) => state.normalOcuuKey,
  ocuuClassName: (state) => state.ocuuClassName,
  noneOcrCheckIdCard: (state) => state.noneOcrCheckIdCard,
};

const mutations = {
  INIT_DATA(state, payload) {
    Object.assign(state, payload);
  },
  SET_COUNTRY_LIST(state, payload) {
    state.nationList = payload;
  },
};
const actions = {
  async initDictionaryCode({ commit, dispatch }, data) {
    commit("INIT_DATA", data);
    dispatch("getGuoJiaJson", data);
    /* === 民盛通用码表配置 === */
    // 2.居民税收类型
    let ssDemo = ["0", "1", "2"],
      sslist = [];
    if (data.shuiShouArr && data.shuiShouArr.length > 0) {
      ssDemo = data.shuiShouArr;
    }
    sslist = crsCodeList.filter((item) => ssDemo.includes(item.keyId));
    commit("INIT_DATA", {
      crsIdTypeList: sslist,
    });
  },
  getGuoJiaJson({ state, commit, dispatch }, data = {}) {
    if (data.nationList && data.nationList.length > 0) {
      commit("SET_COUNTRY_LIST", data.nationList);
    } else {
      if (state.nationList.length > 0) return;
      dispatch("json/getJson9Config", "country", {
        root: true,
      }).then((res) => {
        commit("SET_COUNTRY_LIST", res);
      });
    }
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
